/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package VISUAL;
import DAL.ConectaBd;
import java.sql.*;
import java.util.Locale;
import javax.swing.JOptionPane;
import net.proteanit.sql.DbUtils;

/**
 *
 * @author MAYCON
 */
public class frmCadFornecedor extends javax.swing.JInternalFrame {
    
    Connection conecta;
    PreparedStatement pst;
    ResultSet rs;

    /**
     * Creates new form frmCadFornecedor
     */
    public frmCadFornecedor() throws ClassNotFoundException {
        initComponents();
        this.setLocation(300,100);
        conecta = ConectaBd.conectabd();
        listarFornecedores();
    }
    
    public void listarFornecedores()//Método para aparecer os dados dos fornecedores do banco na tabela
    {
        String sql = "Select *from cadfornecedor order by id Asc";// order by id Asc para deixar em ordem por código crescente
        try
        {
            pst = conecta.prepareStatement(sql);
            rs = pst.executeQuery();
            tblFornecedor01.setModel(DbUtils.resultSetToTableModel(rs));
            
        }
        catch(SQLException error)
        {
            JOptionPane.showMessageDialog(null,error);
        }    
    }
    
    public void pesquisarFornecedor()//Método a qual irá funcionar o campo pesquisar
    {
        String sql = "Select *from cadfornecedor where razao like ?";
        
        try
        {
            pst = conecta.prepareStatement(sql);
            pst.setString(1,txtPesquisarFornecedor.getText()+"%");
            rs = pst.executeQuery();
            tblFornecedor01.setModel(DbUtils.resultSetToTableModel(rs));
            
        }
        catch(SQLException error)
        {
            JOptionPane.showMessageDialog(null,error);
        }    
    }
    
    public void salvarFornecedor()//Método botão salvar fornecedor no banco de dados
    {
        String sql = "Insert into cadfornecedor (razao,fantasia,cep,endereco,bairro,cidade,estado,cnpj,incricao,email,site,telefone,fax,celular,nomecontato,skype,obs)values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        try
        {
            pst = conecta.prepareStatement(sql);
            pst.setString(1,txtRazaoSocialFornecedor.getText());
            pst.setString(2,txtNomeFantasiaFornecedor.getText());
            pst.setString(3,txtCepFornecedor.getText());
            pst.setString(4,txtEnderecoFornecedor.getText());
            pst.setString(5,txtBairroFornecedor.getText());
            pst.setString(6,txtCidadeFornecedor.getText());
            pst.setString(7,txtEstadoFornecedor.getText());
            pst.setString(8,txtCnpjFornecedor.getText());
            pst.setString(9,txtInscricaoFornecedor.getText());
            pst.setString(10,txtEmailFornecedor.getText());
            pst.setString(11,txtSiteFornecedor.getText());
            pst.setString(12,txtTelefoneFornecedor.getText());
            pst.setString(13,txtFaxFornecedor.getText());
            pst.setString(14,txtCelularFornecedor.getText());
            pst.setString(15,txtNomeContatoFornecedor.getText());
            pst.setString(16,txtSkypeFornecedor.getText());
            pst.setString(17,txtObsFornecedor.getText());  
            
            
            
            
            pst.execute();
            JOptionPane.showMessageDialog(null, "Cadastrado com sucesso!","Cadastrado com sucesso",JOptionPane.INFORMATION_MESSAGE);
            listarFornecedores();
        }
        catch (SQLException error)
        {
            JOptionPane.showMessageDialog(null, error);
        }
    }
    
    public void mostrarFornecedoresCampo()//Este metodo ao clicar no cliente irá mostrar nos campos e após pressionar delete irá excluir
    {
        int seleciona = tblFornecedor01.getSelectedRow();
        txtIdFornecedor.setText(tblFornecedor01.getModel().getValueAt(seleciona,0).toString());
        txtRazaoSocialFornecedor.setText(tblFornecedor01.getModel().getValueAt(seleciona,1).toString());
        txtNomeFantasiaFornecedor.setText(tblFornecedor01.getModel().getValueAt(seleciona,2).toString());
        txtCepFornecedor.setText(tblFornecedor01.getModel().getValueAt(seleciona,3).toString());
        txtEnderecoFornecedor.setText(tblFornecedor01.getModel().getValueAt(seleciona,4).toString());
        txtBairroFornecedor.setText(tblFornecedor01.getModel().getValueAt(seleciona,5).toString());
        txtCidadeFornecedor.setText(tblFornecedor01.getModel().getValueAt(seleciona,6).toString());
        txtEstadoFornecedor.setText(tblFornecedor01.getModel().getValueAt(seleciona,7).toString());
        txtCnpjFornecedor.setText(tblFornecedor01.getModel().getValueAt(seleciona,8).toString());
        txtInscricaoFornecedor.setText(tblFornecedor01.getModel().getValueAt(seleciona,9).toString());
        txtEmailFornecedor.setText(tblFornecedor01.getModel().getValueAt(seleciona,10).toString());
        txtSiteFornecedor.setText(tblFornecedor01.getModel().getValueAt(seleciona,11).toString());
        txtTelefoneFornecedor.setText(tblFornecedor01.getModel().getValueAt(seleciona,12).toString());
        txtFaxFornecedor.setText(tblFornecedor01.getModel().getValueAt(seleciona,13).toString());
        txtCelularFornecedor.setText(tblFornecedor01.getModel().getValueAt(seleciona,14).toString());
        txtNomeContatoFornecedor.setText(tblFornecedor01.getModel().getValueAt(seleciona,15).toString());
        txtSkypeFornecedor.setText(tblFornecedor01.getModel().getValueAt(seleciona,16).toString());
        txtObsFornecedor.setText(tblFornecedor01.getModel().getValueAt(seleciona,17).toString());
        
    }
    
    public void editarFornecedor()//metodo para editar os usuários ao clicar na tabela vai para os campos e após clica no botão
    {
        String sql = "Update cadfornecedor set razao = ?,fantasia = ?,cep = ?,endereco = ?,bairro = ?,cidade = ?,estado = ?,cnpj = ?,incricao = ?,email = ?,site = ?,telefone = ?,fax = ?,celular = ?,nomecontato = ?,skype = ?,obs = ? where id = ?"; 
        
        try
        {
            pst = conecta.prepareStatement(sql);
            pst.setString(1,txtRazaoSocialFornecedor.getText());
            pst.setString(2,txtNomeFantasiaFornecedor.getText());
            pst.setString(3,txtCepFornecedor.getText());
            pst.setString(4,txtEnderecoFornecedor.getText());
            pst.setString(5,txtBairroFornecedor.getText());
            pst.setString(6,txtCidadeFornecedor.getText());
            pst.setString(7,txtEstadoFornecedor.getText());
            pst.setString(8,txtCnpjFornecedor.getText());
            pst.setString(9,txtInscricaoFornecedor.getText());
            pst.setString(10,txtEmailFornecedor.getText());
            pst.setString(11,txtSiteFornecedor.getText());
            pst.setString(12,txtTelefoneFornecedor.getText());
            pst.setString(13,txtFaxFornecedor.getText());
            pst.setString(14,txtCelularFornecedor.getText());
            pst.setString(15,txtNomeContatoFornecedor.getText());
            pst.setString(16,txtSkypeFornecedor.getText());
            pst.setString(17,txtObsFornecedor.getText());    
            pst.setInt(18,Integer.parseInt(txtIdFornecedor.getText()));
            pst.executeUpdate();
            JOptionPane.showMessageDialog(null,"Cadastro atualizado com sucesso");
            listarFornecedores();
        }
        catch (SQLException error)
        {
            JOptionPane.showMessageDialog(null, error);
        }    
    }
    
    public void deletarFornecedor()
    {
        String sql = "Delete from cadfornecedor where id = ?";//Metodo para exclusão de cliente pelo botão
        
        try
        {
            pst = conecta.prepareStatement(sql);
            pst.setInt(1,Integer.parseInt(txtIdFornecedor.getText()));
            pst.execute();
            listarFornecedores();
        }
        catch(SQLException error)
        {
            JOptionPane.showMessageDialog(null,error);
            
            
        }
    }
    
    public void limparCampos()//metodo para funcionar o botão limpar ao clica-lo
    {
         txtIdFornecedor.setText("");
        txtRazaoSocialFornecedor.setText("");
        txtNomeFantasiaFornecedor.setText("");
        txtCepFornecedor.setText("");
        txtEnderecoFornecedor.setText("");
        txtBairroFornecedor.setText("");
        txtCidadeFornecedor.setText("");
        txtEstadoFornecedor.setText("");
        txtCnpjFornecedor.setText("");
        txtInscricaoFornecedor.setText("");
        txtEmailFornecedor.setText("");
        txtSiteFornecedor.setText("");
        txtTelefoneFornecedor.setText("");
        txtFaxFornecedor.setText("");
        txtCelularFornecedor.setText("");
        txtNomeContatoFornecedor.setText("");
        txtSkypeFornecedor.setText("");
        txtObsFornecedor.setText("");
        
    }  

    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jLabel17 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        txtInscricaoFornecedor = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        txtRazaoSocialFornecedor = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        txtEstadoFornecedor = new javax.swing.JTextField();
        txtBairroFornecedor = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        txtNomeFantasiaFornecedor = new javax.swing.JTextField();
        txtIdFornecedor = new javax.swing.JTextField();
        txtCnpjFornecedor = new javax.swing.JFormattedTextField();
        jLabel13 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtTelefoneFornecedor = new javax.swing.JFormattedTextField();
        jLabel14 = new javax.swing.JLabel();
        txtEnderecoFornecedor = new javax.swing.JTextField();
        txtCepFornecedor = new javax.swing.JFormattedTextField();
        txtCidadeFornecedor = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtEmailFornecedor = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtCelularFornecedor = new javax.swing.JFormattedTextField();
        jLabel1 = new javax.swing.JLabel();
        txtSiteFornecedor = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtFaxFornecedor = new javax.swing.JFormattedTextField();
        jLabel11 = new javax.swing.JLabel();
        txtSkypeFornecedor = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtNomeContatoFornecedor = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        txtObsFornecedor = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblFornecedor01 = new javax.swing.JTable();
        txtPesquisarFornecedor = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();

        setClosable(true);
        setIconifiable(true);
        setTitle("Cadastro de Fornecedores");
        setMaximumSize(new java.awt.Dimension(0, 0));
        setMinimumSize(new java.awt.Dimension(0, 0));
        setPreferredSize(new java.awt.Dimension(740, 680));

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Dados do Fornecedor"));

        jLabel17.setText("CIDADE:");

        jLabel19.setText("ENDEREÇO:");

        jLabel8.setText("TELEFONE:");

        jLabel10.setText("CNPJ:");

        jLabel9.setText("INSCRIÇÃO:");

        jLabel16.setText("ID:");

        jLabel15.setText("CEP:");

        txtIdFornecedor.setEnabled(false);

        try {
            txtCnpjFornecedor.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###.###.####/##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jLabel13.setText("RAZÃO SOCIAL:");

        jLabel7.setText("ESTADO:");

        try {
            txtTelefoneFornecedor.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jLabel14.setText("NOME FANTASIA:");

        try {
            txtCepFornecedor.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###-###")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jLabel18.setText("BAIRRO:");

        jLabel2.setText("E-MAIL:");

        jLabel4.setText("CELULAR:");

        try {
            txtCelularFornecedor.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jLabel1.setText("SITE:");

        jLabel3.setText("FAX:");

        try {
            txtFaxFornecedor.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jLabel11.setText("SKYPE:");

        jLabel5.setText("NOME CONTATO:");

        jLabel12.setText("OBS.:");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(jLabel10)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel13)
                            .addComponent(jLabel14)
                            .addComponent(jLabel15)
                            .addComponent(jLabel16)
                            .addComponent(jLabel18)
                            .addComponent(jLabel19)
                            .addComponent(jLabel12)
                            .addComponent(jLabel17))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtObsFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 568, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(jPanel2Layout.createSequentialGroup()
                                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(txtRazaoSocialFornecedor, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE)
                                        .addComponent(txtNomeFantasiaFornecedor, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE)
                                        .addComponent(txtIdFornecedor, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(txtCepFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel2Layout.createSequentialGroup()
                                            .addComponent(jLabel9)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(txtInscricaoFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(jPanel2Layout.createSequentialGroup()
                                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(jPanel2Layout.createSequentialGroup()
                                                    .addComponent(jLabel8)
                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED))
                                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                                    .addComponent(jLabel3)
                                                    .addGap(23, 23, 23)))
                                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                .addComponent(txtFaxFornecedor)
                                                .addComponent(txtCelularFornecedor)
                                                .addComponent(txtTelefoneFornecedor, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE)))
                                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(jLabel11)
                                            .addComponent(jLabel4))))
                                .addGroup(jPanel2Layout.createSequentialGroup()
                                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(txtBairroFornecedor, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE)
                                        .addComponent(txtCidadeFornecedor, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE)
                                        .addComponent(txtEstadoFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(txtCnpjFornecedor, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel2Layout.createSequentialGroup()
                                            .addComponent(jLabel5)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(txtNomeContatoFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(jPanel2Layout.createSequentialGroup()
                                            .addGap(19, 19, 19)
                                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel1)
                                                .addComponent(jLabel2))
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(txtSiteFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(txtEmailFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(txtSkypeFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                                .addComponent(txtEnderecoFornecedor, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE)))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {txtBairroFornecedor, txtCidadeFornecedor, txtCnpjFornecedor, txtEnderecoFornecedor, txtInscricaoFornecedor, txtNomeFantasiaFornecedor, txtRazaoSocialFornecedor, txtTelefoneFornecedor});

        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(txtIdFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtRazaoSocialFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel13)
                            .addComponent(jLabel9)
                            .addComponent(txtInscricaoFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtNomeFantasiaFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel14)
                            .addComponent(jLabel8)
                            .addComponent(txtTelefoneFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel15)
                            .addComponent(txtCepFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4)
                            .addComponent(txtCelularFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel16))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtEnderecoFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel19)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtFaxFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel18)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel17))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(txtEmailFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtBairroFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(txtSiteFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel1))
                            .addComponent(txtCidadeFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(10, 10, 10)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel7)
                        .addComponent(txtSkypeFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtEstadoFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel11)))
                .addGap(9, 9, 9)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(txtCnpjFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(txtNomeContatoFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel12)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(txtObsFornecedor, javax.swing.GroupLayout.DEFAULT_SIZE, 85, Short.MAX_VALUE))
                .addContainerGap())
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {txtBairroFornecedor, txtCepFornecedor, txtCidadeFornecedor, txtCnpjFornecedor, txtEnderecoFornecedor, txtEstadoFornecedor, txtIdFornecedor, txtInscricaoFornecedor, txtNomeFantasiaFornecedor, txtRazaoSocialFornecedor, txtTelefoneFornecedor});

        jPanel2Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {txtCelularFornecedor, txtEmailFornecedor, txtFaxFornecedor, txtNomeContatoFornecedor, txtSiteFornecedor, txtSkypeFornecedor});

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ICONES/disk.png"))); // NOI18N
        jButton1.setText("Cadastrar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ICONES/arrow_refresh.png"))); // NOI18N
        jButton2.setText("Editar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ICONES/cancel.png"))); // NOI18N
        jButton3.setText("Deletar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ICONES/delete.png"))); // NOI18N
        jButton4.setText("Limpar");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Listar Fornecedores"));

        tblFornecedor01.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblFornecedor01.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblFornecedor01MouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tblFornecedor01);

        txtPesquisarFornecedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPesquisarFornecedorActionPerformed(evt);
            }
        });
        txtPesquisarFornecedor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtPesquisarFornecedorKeyReleased(evt);
            }
        });

        jLabel21.setText("RAZÃO SOCIAL:");

        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ICONES/zoom.png"))); // NOI18N
        jLabel6.setText("BUSCAR");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel21)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtPesquisarFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 482, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel6)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtPesquisarFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel21)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton4)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton1, jButton2, jButton3, jButton4});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(2, 2, 2)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2)
                    .addComponent(jButton3)
                    .addComponent(jButton4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jButton1, jButton2, jButton3, jButton4});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // Este é o botão fornecedor ele está chamando o método :
        salvarFornecedor();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // Este é o botão do atualizar, ele irá chamar o método:
        editarFornecedor();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void tblFornecedor01MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblFornecedor01MouseClicked
        // Chamáda de tabela para aparecer os dados da tabela nos campos:
        mostrarFornecedoresCampo();
    }//GEN-LAST:event_tblFornecedor01MouseClicked

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // Botão com método para deletar fornecedor:
        deletarFornecedor();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // Botão com método para limpar dados dos campos fornecedor:
        limparCampos();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void txtPesquisarFornecedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPesquisarFornecedorActionPerformed
        // Método sem uso
    }//GEN-LAST:event_txtPesquisarFornecedorActionPerformed

    private void txtPesquisarFornecedorKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPesquisarFornecedorKeyReleased
        // Método que vai puxar o campo pesquisar:
        pesquisarFornecedor();
    }//GEN-LAST:event_txtPesquisarFornecedorKeyReleased


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable tblFornecedor01;
    private javax.swing.JTextField txtBairroFornecedor;
    private javax.swing.JFormattedTextField txtCelularFornecedor;
    private javax.swing.JFormattedTextField txtCepFornecedor;
    private javax.swing.JTextField txtCidadeFornecedor;
    private javax.swing.JFormattedTextField txtCnpjFornecedor;
    private javax.swing.JTextField txtEmailFornecedor;
    private javax.swing.JTextField txtEnderecoFornecedor;
    private javax.swing.JTextField txtEstadoFornecedor;
    private javax.swing.JFormattedTextField txtFaxFornecedor;
    private javax.swing.JTextField txtIdFornecedor;
    private javax.swing.JTextField txtInscricaoFornecedor;
    private javax.swing.JTextField txtNomeContatoFornecedor;
    private javax.swing.JTextField txtNomeFantasiaFornecedor;
    private javax.swing.JTextField txtObsFornecedor;
    private javax.swing.JTextField txtPesquisarFornecedor;
    private javax.swing.JTextField txtRazaoSocialFornecedor;
    private javax.swing.JTextField txtSiteFornecedor;
    private javax.swing.JTextField txtSkypeFornecedor;
    private javax.swing.JFormattedTextField txtTelefoneFornecedor;
    // End of variables declaration//GEN-END:variables
}
